//package com.sunop.pantiai.controller;
//
//import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
//import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
//import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
//import com.alibaba.dashscope.common.MultiModalMessage;
//import com.alibaba.dashscope.common.Role;
//import com.alibaba.dashscope.exception.ApiException;
//import com.alibaba.dashscope.exception.NoApiKeyException;
//import com.alibaba.dashscope.exception.UploadFileException;
//import com.google.gson.Gson;
//import io.reactivex.Flowable;
//import org.springframework.web.bind.annotation.*;
//import reactor.core.publisher.Flux;
//
//import java.util.Arrays;
//import java.util.HashMap;
//
//@RestController
//@RequestMapping("/api/multimodal")
//public class MultiModalController {
//
//    @PostMapping("/stream")
//    public Flux<String> streamMultimodalConversation(@RequestBody MultiModalRequest request) {
//        try {
//            MultiModalConversation conv = new MultiModalConversation();
//
//            MultiModalMessage userMessage = MultiModalMessage.builder()
//                    .role(Role.USER.getValue())
//                    .content(Arrays.asList(
//                            new HashMap<String, Object>() {{ put("image", request.getImageUrl()); }},
//                            new HashMap<String, Object>() {{ put("text", request.getQuestion()); }}
//                    ))
//                    .build();
//
//            MultiModalConversationParam param = MultiModalConversationParam.builder()
//                    .message(userMessage)
//                    .build();
//
//            Flowable<MultiModalConversationResult> result = conv.streamCall(param);
//            Gson gson = new Gson();
//
//            return Flux.from(result.map(item -> {
//                if (item.getOutput() == null) {
//                    throw new RuntimeException("API返回output为null，响应内容: " + gson.toJson(item));
//                }
//                return gson.toJson(item.getOutput());
//            }));
//
//        } catch (Exception e) {
//            return Flux.error(new RuntimeException("调用API失败: " + e.getMessage(), e));
//        }
//    }
//
//    // 请求参数类
//    public static class MultiModalRequest {
//        private String imageUrl;
//        private String question;
//
//        // getters and setters
//        public String getImageUrl() {
//            return imageUrl;
//        }
//
//        public void setImageUrl(String imageUrl) {
//            this.imageUrl = imageUrl;
//        }
//
//        public String getQuestion() {
//            return question;
//        }
//
//        public void setQuestion(String question) {
//            this.question = question;
//        }
//    }
//}